var express = require('express');
var router = express.Router();
var url = require('url')

// 数据脚本
var data1111 = require('./data/1111.js');
var data1112 = require('./data/1112.js');
var data1113 = require('./data/1113.js');
var data1114 = require('./data/1114.js');
var data2013 = require('./data/2013.js');
var data2015 = require('./data/2015.js');
var data2111 = require('./data/2111.js');
var data2113 = require('./data/2113.js');
var data2211 = require('./data/2211.js');
var data2212 = require('./data/2212.js');


// Index start
const BannerData = require('./Index/banner');
const GambitlistData = require('./Index/gambitlist');
const ParticularsData = require('./Index/particulars');
const LungtestData = require('./Index/lungtest');
// Index end

// shop start
const ShoplistData = require('./Worksshop/shoplist');
// shop end

// mine start
const TestListData = require('./Mine/testList');
// mine end

// Personal start
const AddrData = require('./Personal/Addr');
const SymptomaticData = require('./Personal/symptomatic');
// Personal end

// Index start
// 首页轮播数据
router.get('/api/banner',function(req,res){
  res.send(BannerData)
})

router.get('/api/gambitlist',function(req,res){
  res.send(GambitlistData)
})

router.get('/api/particulars',function(req,res){
  var query = url.parse(req.url,true).query;
  console.log('商品Id:'+query.id);
  res.send(ParticularsData)
})
router.get('/api/lungtest',function(req,res){
  var query = url.parse(req.url,true).query;
  console.log('第'+query.page+'题');
  res.send(LungtestData[query.page-1])
})
// Index end

// shop start
// 分类商品列表数据
router.get("/api/goodslist",function(req,res){
  var path_url = url.parse(req.url,true);
  var query = path_url.query;
  var type_id = query.typeId;
  var size = query.size;
  var offset = query.offset ? query.offset : 0;
  var data = eval('data'+type_id);
  if(data){
    var result = data.slice(offset,offset+size);
    res.send(result)
  }else{
    res.send({
      details: null,
      error_code: 22000
    })
  }
});

// shop end

// Personal start
router.get('/api/addr',function(req,res){
  res.send(AddrData)
})
router.get('/api/symptomatic',function(req,res){
  var query = url.parse(req.url,true).query;
  console.log('用户Id:'+query.userid);
  res.send(SymptomaticData)
})
// Personal end

// mine start
router.get('/api/test',function(req,res){
  res.send(TestListData)
})
// mine end

module.exports = router;
